"use strict";

var _class, _class2, _descriptor, _temp;

function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }

function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }

// 装饰器 可以装饰类  类的属性  类的原型上的方法
// experimentalDecorators  设置这个选项编辑器不报错
// babel 又要添加插件 才行  
var Animal = flag(_class = (_class2 = (_temp = /*#__PURE__*/function () {
  function Animal() {
    _classCallCheck(this, Animal);

    _initializerDefineProperty(this, "PI", _descriptor, this);

    this.name = 'xxx';
  }

  _createClass(Animal, [{
    key: "say",
    value: function say() {
      console.log('你好');
    }
  }]);

  return Animal;
}(), _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "PI", [readOnly], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return 3.14;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "say", [before], Object.getOwnPropertyDescriptor(_class2.prototype, "say"), _class2.prototype)), _class2)) || _class; // 装饰类  接收类的构造函数


function flag(constructor) {
  console.log(constructor);
} // 属性的装饰器


function readOnly(target, property, descriptor) {
  console.log(target); // 类的原型

  descriptor.writable = false;
} // 方法的装饰器


function before(target, property, descriptor) {
  // 
  // console.log(before)
  var old = descriptor.value;

  descriptor.value = function () {
    console.log('before');
    old();
  };
}

var a = new Animal();
a.say();
